package com.xianye.erp.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
@Component
public class LoginInterceptor extends HandlerInterceptorAdapter{

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		HttpSession session = request.getSession();
		if(request.getServletPath().startsWith("/user/")
				||request.getServletPath().startsWith("/user/login")
				||request.getServletPath().startsWith("/api_auth")
				||request.getServletPath().startsWith("/test")
				||request.getServletPath().startsWith("/test1")
				||request.getServletPath().startsWith("/test2")
				||request.getServletPath().startsWith("/test32")
				) {
			System.out.println("不过滤");
			return true;
		}
		System.out.println("开始过滤");
		if(session.getAttribute("user")!=null){
			return true;
		}
	    response.sendRedirect(request.getContextPath() + "/user/");
		return false;
	}
}
